﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Entity;

namespace Helper
{
    public class CEP
    {
        public static Endereco Endereco(string CodCEP)
        {
            Endereco end = new Endereco();

            try
            {
                XmlDocument xdoc = new XmlDocument();
                xdoc.Load("http://cep.caosdevelopers.com/web_cep.php?cep=" + CodCEP);

                string address = (xdoc.SelectSingleNode("webservicecep/logradouro")).InnerText;
                string town = (xdoc.SelectSingleNode("webservicecep/bairro")).InnerText;
                string city = (xdoc.SelectSingleNode("webservicecep/cidade")).InnerText;
                string uf = (xdoc.SelectSingleNode("webservicecep/uf")).InnerText;

                end.LOGRADOURO = address;
                end.CidadeNome = city;
                end.BAIRRO = town;
                end.UF = uf;
               
            }
            catch
            {
                end = null;
            }

            return end;
        }
    }
}
